import java.util.concurrent.locks.ReentrantLock;

public class Demo13 {

    public  static  int num;

    public static void main(String[] args) throws InterruptedException {

        ReentrantLock reentrantLock = new ReentrantLock();

        Thread thread = new Thread(() -> {
            for (int i = 0; i < 5000; i++) {
                reentrantLock.lock();
                try{
                    num++;
                }finally {
                    reentrantLock.unlock();
                }

            }
        });

        Thread thread2 = new Thread(() -> {
            for (int i = 0; i < 5000; i++) {
                reentrantLock.lock();
                try{
                    num++;
                }finally {
                    reentrantLock.unlock();
                }
            }
        });

        thread.start();
        thread2.start();
        thread.join();
        thread2.join();
        System.out.println(num);
    }
}
